import {getCityApi,getAddressListApi,createAddressApi,editAddressApi,delAddressApi,defAddressApi} from '@/service/index.js'

export default{
	namespaced: true,
	state:{//存放状态
		cityList:uni.getStorageSync('cityList')||'',
		addressList:uni.getStorageSync('addressList')||''
	},
	mutations:{
		// 储存城市信息
		CITY_LIST(state,data){
			state.cityList=data
			uni.setStorageSync('cityList',data)
		},
		// 储存地址列表
		ADDRESS_LIST(state,data){
			state.addressList=data
			uni.setStorageSync('addressList',data)
		}
	},
	actions:{
		// 获取城市
		async getCityList({commit}){
			let res=await getCityApi()
			if(res.statusCode===200){
				commit('CITY_LIST',res.data.result)
			}
		},
		// 获取自己地址列表
		async getAddressList({commit}){
			let res=await getAddressListApi()
			if(res.statusCode===200){
				commit('ADDRESS_LIST',res.data.result)
			}
		},
		// 创建地址
		async createAddress({commit},data){
			let res=await createAddressApi(data)
		},
		// 更新地址
		async editAddress({commit},data){
			let res=await editAddressApi(data.id,data)
		},
		// 设置默认地址
		async defAddress({commit},id){
			let res=await defAddressApi(id)
		},
		// 删除地址
		async delAddress({commit},id){
			let res=await delAddressApi(id)
			console.log(res);
		}
	},
	getters:{
		
	}
}